<?php


namespace app\shop\model;


use think\Model;

class SpecItemModel extends Model
{
    protected $table = 'dp_spec_item';
    protected $pk = 'id';
    protected $field = true;



    public static function getList($type_id=0)
    {
        if($type_id==0){
            return self::with('type')->paginate(10);
        }else{
            return self::with('type')->where('type_id',$type_id)->paginate(10);
        }
    }

    public static function addItem($_data, $id=0)
    {
        $data =[];
        foreach ($_data as $k){
            $data[$k]['spec_id'] = $id;
            $data[$k]['item'] = $k;
        }
        self::destroy(['spec_id' => $id]);
        $user = new self();
        return $user->saveAll($data);

    }

    public static function getRes($id=0)
    {
        return self::where('spec_id',$id)->column('item');

    }

    public static function getColumn()
    {
        return self::column('item,spec_id','id');
    }

    public static function getIdList($spec_id=0)
    {
        return self::where("spec_id",$spec_id)->order('id')->column('item,spec_id','id');
    }
}